#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=2e3+100;
typedef long long LL;
inline LL read(){LL x=0,f=1;char ch=getchar();	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
struct P{
    LL t,l,r;
};
P a[maxn];
bool check(P A,P B){
     LL AR=A.r;LL BL=B.l;
     if(AR>BL){
        return true;
     }
     else if(AR==BL){
        if(A.t==2||A.t==4||B.t==3||B.t==4) return false;
        else return true;
     }
     else return false;
}
bool cmp(P A,P B){
     if(A.l==B.l){
        return A.r<B.r;
     }
     return A.l<B.l;
}
int main(void){
   	cin.tie(0);std::ios::sync_with_stdio(false);
    LL n;cin>>n;
    for(LL i=1;i<=n;i++){
        cin>>a[i].t>>a[i].l>>a[i].r;
    }
    sort(a+1,a+1+n,cmp);
    LL ans=0;
    for(LL i=1;i<=n;i++){
        for(LL j=i+1;j<=n;j++){
            if(check(a[i],a[j])) ans++;
        }
    }
    cout<<ans<<"\n";
   	return 0;
}
